package android.slc.user.ui.ud.delegate

import android.slc.adapter.SelectBox
import android.slc.appbase.ui.vd.BaseListVd
import android.slc.extras.user.entity.SysDept
import android.slc.user.R
import android.slc.user.ui.ud.adapter.DeptUserInfoMultipleAdapter
import android.slc.user.ui.ud.vmbox.DeptUserListMultipleVmBox
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.android.material.checkbox.MaterialCheckBox
import java.io.Serializable

/**
 *
 * @Description:
 * @Author: sunlunchang
 * @CreateDate: 2021/12/06 下午 2:55
 *
 */
class DeptUserListMultipleDelegate : BaseListVd<Serializable, DeptUserListMultipleVmBox>() {
    override fun getAdapter(list: MutableList<Serializable>): BaseQuickAdapter<Serializable, BaseViewHolder> {
        return DeptUserInfoMultipleAdapter(list)
    }

    override fun onAdapterItemClick(
        adapter: BaseQuickAdapter<Serializable, BaseViewHolder>,
        view: View,
        position: Int
    ) {
        val itemData: Serializable = adapter.getItem(position)
        if (itemData is SysDept) {
            super.onAdapterItemClick(adapter, view, position)
        } else if (itemData is SelectBox<*>) {
            vmBox.select(position, itemData as SelectBox<Serializable>)
            view.findViewById<MaterialCheckBox>(R.id.checkbox).isChecked = itemData.isChecked
        }
    }

}